﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "GmInplaceEdit.h"
#include "IExternalObject.h"
#include "DbDataSchema.h"
#include "ElementId.h"

namespace gcmp
{
    class IDocument;
    class IElement;
    class IGraphicsStyleData;
    class IGraphicsMaterialData;
    class IFillPatternData;
    class ILineTypeData;

    // 相机构件
    class GM_INPLACE_EDIT_EXPORT InplaceEditProjectStyleMaterialMap : public NdbObjectSchematic, public IExternalObject
    {
        CANNOT_COPY_OR_ASSIGN(InplaceEditProjectStyleMaterialMap);
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, InplaceEditProjectStyleMaterialMap, gcmp::NdbObjectSchematic, F8DDFE8A - 20E5 - 4539 - 8C6E - ABC64F6A9A19, gminplaceedit, gcmp::IExternalObject)
            DATA_TRANSIENT(IElement*, pOwnerElement)
            MAP_DATA(Int64, ElementId, StyleMap)
            MAP_DATA(Int64, ElementId, MaterialMap)
            MAP_DATA(Int64, ElementId, FillPatternMap)
            MAP_DATA(Int64, ElementId, LineTypeNewMap)
        DBOBJECT_DATA_END
    
    public:
        static const InplaceEditProjectStyleMaterialMap *Get(IDocument *pDoc);
        static InplaceEditProjectStyleMaterialMap *GetFw(IDocument *pDoc);
        static InplaceEditProjectStyleMaterialMap *Create(IDocument *pDoc);

        ElementId GetFamilyStyleId(ElementId projectStyleId) const;
        ElementId GetFamilyMaterialId(ElementId projectMaterialId) const;
        ElementId GetFamilyFillPatternId(ElementId projectGenericId) const;
        ElementId GetFamilyLineTypeNewId(ElementId projectGenericId) const;

        bool AddProjectStyle(ElementId projectStyleId, const IGraphicsStyleData* pStyleData);
        bool AddProjectMaterial(ElementId projectMaterialId, const IGraphicsMaterialData* pMaterialData);
        bool AddProjectFillPattern(ElementId projectGenericId, const IFillPatternData* pFillPatternData);
        bool AddProjectLineTypeNew(ElementId projectGenericId, const ILineTypeData* pLineTypeData);

    public:
        IDocument* GetDocument() const;
        ElementId GetOwnerElementId() const;


#pragma region IExternalObject接口
    public:
        virtual bool SetOwnerElement(IElement* pOwnerElement) override;
        virtual IElement* GetOwnerElement() override { return m_pOwnerElement; }
        virtual const IElement* GetOwnerElement() const override { return m_pOwnerElement; }
        virtual NdbObject* GetTopOwnerObject() const override;

#pragma region 关联更新
        virtual void UpdateForWeakParentDeletion(const std::set<ElementId>& deletedElementIds) override;
        virtual void ReportParents(IElementParentReporter& reporter) const override;
#pragma endregion 关联更新

#pragma region 其他
        virtual bool FinishEditing() override;
#pragma endregion 其他

#pragma endregion IExternalObject接口
    };
}

